
import {useNavigate} from 'react-router-dom'
import NavTop from '../components/navtop'
import '../assets/css/login.css'
import logo from '../assets/images/logo1.png'
import { Login } from '../request/app.js'
import { useState } from 'react'
function Home() {
    const [user, setUser] = useState({
        phone:'',
        password:''
    })
    const navigate=useNavigate()
    function login() {
        Login(user)
        .then(res => {
                console.log(res);
                if (res.code == 200) {
                    alert('登录成功')
                    sessionStorage.setItem('userInfo', JSON.stringify(res.list))
                    navigate('/index/home')
                }else{
                    alert(res.msg)
                    window.location.reload()
                    return
                }
            })
    }
    function changeinfo(type, e) {
        setUser({
            ...user,
            [type]: e.target.value
        })
    }
    return (<div>
        <div id="page">
            <NavTop />
            <div className="body">
                <div className="body_center">
                    <img src={logo} alt="" />
                    <div>
                        <input type="text" placeholder='手机号'onChange={changeinfo.bind(this, 'phone')} />
                    </div>
                    <div className='testCode'>
                        <input type="text" placeholder='验证码' onChange={changeinfo.bind(this, 'password')} />
                        <button>获取验证码</button>
                    </div>
                    <button className='login' onClick={() => login()}>登录</button>
                </div>
            </div>
        </div>
    </div >)
}
export default Home